package com.suluyun.presenter;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.suluyun.model.UserBean;
import com.suluyun.view.LoginView;

import static android.support.constraint.Constraints.TAG;


public class LoginPresenterCompl implements LoginPresenter {
    LoginView iLoginView;
    UserBean user;
    Handler handler;

    public LoginPresenterCompl(LoginView iLoginView) {
        this.iLoginView = iLoginView;
        initUser();
        handler = new Handler(Looper.getMainLooper());
    }

    @Override
    public void doLogin(String name, String passwd) {
        final Boolean result = (name.equals(user.getName()) && passwd.equals(user.getPasswd()));
        Log.d(TAG, "doLogin: " + user.getName() + "2" + name);
        Log.d(TAG, "doLogin: " + user.getPasswd() + "2" + passwd);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                iLoginView.loginResult(result);
            }
        }, 2000);

    }

    @Override
    public void setProgressBarVisiblity(int visiblity){
        iLoginView.onSetProgressBarVisibility(visiblity);
    }

    //直接初始化账号，后期需重构加入数据库访问
    private void initUser(){
        user = new UserBean();
        user.setName("a");
        user.setPasswd("b");
    }
}
